<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Staticinfo extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->checkAdmin($this->session->userdata('admin_id'), $this->session->userdata('permission_verify'));
        $this->data['controller'] = 'staticinfo';
        $this->load->model('Mstaticinfo');
        $this->_per = $this->checkPerMission($this->session->userdata('admin'), $this->session->userdata('SessionPermisson'), 6, $this->session->userdata('admin_id'));
    }
    
    public function logoGpeople()
    {
        if($this->_per->read != 1 && $this->_per->edit != 3)
        {
            $this->redirect_notification($this->data['page'],array('Thông Báo', '<center><strong>Bạn không có quyền này</strong></center>'),'thong-bao', 'index');
            exit();
        }
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('logo_gpeople_check', 'Ảnh logo', 'required');
        
        $this->data['data'] = $this->Mstaticinfo->getLogoGpeople();
        if($this->form_validation->run() === TRUE)
        {
            $dataimage = $this->getParamString('logo_gpeople');//die($dataimage);
            
            $dataimage_check = $this->getParamString('logo_gpeople_check');
            $verify_image = $this->getParamString('logo_gpeople_verify');
            if(!in_array($verify_image, array(null, '')))
            {
                if($verify_image != $dataimage_check)
                {
                    @unlink(PROJECT_PATH.'/data/'.$verify_image);
                }
            }
            
            /*if(!in_array($dataimage, array(null, '', '0')))
            {
                $timenow = time().rand(0,9999);
                $nameimagess = 'logo-gpeople.png';
                $path = 'images/logo/';
                @mkdir(PROJECT_PATH.'/data/'.$path, 0301);
                $paths = PROJECT_PATH.'/data/'.$path;
                $arr_exp = array('[removed]', '[removed');
                $exp = str_replace($arr_exp,'',$dataimage);
                $this->savefile($exp,$paths,$nameimagess);
                $img = $path.$nameimagess;
            }else{
                $img = '';
            }*/
            
            $path1 = 'images/logo/';
			@mkdir(PROJECT_PATH.'/data/'.$path1, 0301);
			$config['upload_path'] = '../data/'.$path1;
			$config['allowed_types'] = 'gif|jpg|png';
			$config['max_size']	= '2000';
			$config['max_width']  = '10240';
			$config['max_height']  = '7680';
			$config['encrypt_name'] =  TRUE;// TRUE/FALSE (boolean)
			$this->load->library('upload', $config);
			if( !$this->upload->do_upload('fileupload')){
				$img = '';
			}else{
				$data_img = $this->upload->data();
				$img = $path1.$data_img['file_name'];
			}
            //die($img.'');
            
            $this->data['data'] = $this->Mstaticinfo->logoGpeopleDb($img);
            if($this->data['data'] == 200)
            {
                die('<meta charset="utf-8"><script>alert("Lưu thành công");window.location.href="'.$this->data['baseurl'].'manage/static/logo-gpeople";</script>');
            }
        }
        $this->data['action'] = 'logogpeople';
        $this->load->view('template/layout', $this->data);
    }
    
    public function fanpageFacebook()
    {
        if($this->_per->read != 1 && $this->_per->edit != 3)
        {
            $this->redirect_notification($this->data['page'],array('Thông Báo', '<center><strong>Bạn không có quyền này</strong></center>'),'thong-bao', 'index');
            exit();
        }
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('fanpage', 'Đường dẫn Fanpage', 'required');
        $this->form_validation->set_rules('hotline', 'Hotline', 'required');
        
        $this->data['data'] = $this->Mstaticinfo->getFanpage();
        if($this->form_validation->run() === TRUE)
        {
            $url = $this->getParamString('fanpage');
            $hotline = $this->getParamString('hotline');
            $this->data['data'] = $this->Mstaticinfo->fanpageFacebookDb($url,$hotline);
            if($this->data['data'] == 200)
            {
                die('<meta charset="utf-8"><script>alert("Lưu thành công");window.location.href="'.$this->data['baseurl'].'manage/static/fanpage";</script>');
            }
        }
        $this->data['action'] = 'fanpagefacebook';
        $this->load->view('template/layout', $this->data);
    }
	
	public function distance(){
		if($this->_per->read != 1 && $this->_per->edit != 3)
        {
            $this->redirect_notification($this->data['page'],array('Thông Báo', '<center><strong>Bạn không có quyền này</strong></center>'),'thong-bao', 'index');
            exit();
        }
        $this->load->library('form_validation');
        $this->form_validation->set_rules('distance', 'Khoảng cách hiển thị bản đồ', 'required');
        $this->data['data'] = $this->Mstaticinfo->getDistance();
        if($this->form_validation->run() === TRUE)
        {
            $distance = $this->getParamString('distance');
            $this->data['data'] = $this->Mstaticinfo->distanceDb($distance);
            if($this->data['data'] == 200)
            {
                die('<meta charset="utf-8"><script>alert("Lưu thành công");window.location.href="'.$this->data['baseurl'].'manage/static/distance";</script>');
            }
        }
        $this->data['action'] = 'distance';
        $this->load->view('template/layout', $this->data);
	}
	
	
	public function urlhomeicook(){
		if($this->_per->read != 1 && $this->_per->edit != 3)
        {
            $this->redirect_notification($this->data['page'],array('Thông Báo', '<center><strong>Bạn không có quyền này</strong></center>'),'thong-bao', 'index');
            exit();
        }
        $this->load->library('form_validation');
        $this->form_validation->set_rules('urlhomeicook', 'Đường dẫn trang chủ ICOOK', 'required');
        $this->data['data'] = $this->Mstaticinfo->getUrlHomeIcook(); //die(print_r($this->data['data']));
        if($this->form_validation->run() === TRUE)
        {
            $urlhomeicook = $this->getParamString('urlhomeicook');
            $link_down_app = $this->getParamString('link_down_app');
            $this->data['data'] = $this->Mstaticinfo->UrlHomeIcookDb($urlhomeicook,$link_down_app);
            if($this->data['data'] == 200)
            {
                die('<meta charset="utf-8"><script>alert("Lưu thành công");window.location.href="'.$this->data['baseurl'].'manage/static/urlhomeicook";</script>');
            }
        }
        $this->data['action'] = 'urlhomeicook';
        $this->load->view('template/layout', $this->data);
	}
	
	
	public function versionapp(){
		if($this->_per->read != 1 && $this->_per->edit != 3)
        {
            $this->redirect_notification($this->data['page'],array('Thông Báo', '<center><strong>Bạn không có quyền này</strong></center>'),'thong-bao', 'index');
            exit();
        }
        $this->load->library('form_validation');
        $this->form_validation->set_rules('version', 'Phiên bản', 'required');
        $this->data['data'] = $this->Mstaticinfo->getVersion(); //die(print_r($this->data['data']));
        if($this->form_validation->run() === TRUE)
        {
            $version = $this->getParamString('version');
            $this->data['data'] = $this->Mstaticinfo->updateVersionDb($version);
            if($this->data['data'] == 200)
            {
                die('<meta charset="utf-8"><script>alert("Lưu thành công");window.location.href="'.$this->data['baseurl'].'manage/static/versionapp";</script>');
            }
        }
        $this->data['action'] = 'versionapp';
        $this->load->view('template/layout', $this->data);
	}
    
    public function incentiveprovince(){
        if($this->_per->read != 1 && $this->_per->edit != 3)
        {
            $this->redirect_notification($this->data['page'],array('Thông Báo', '<center><strong>Bạn không có quyền này</strong></center>'),'thong-bao', 'index');
            exit();
        }
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('province', 'Danh sách Tỉnh/Thành phố', 'required');
        $this->data['data'] = $this->Mstaticinfo->getIncentiveProvince(); //die(print_r($this->data['data']));
        $this->data['listProvince'] = $this->Mstaticinfo->listProvince();
        if($this->form_validation->run() === TRUE)
        {
            $province = $this->getParamArray('province');
            $this->data['data'] = $this->Mstaticinfo->updateIncentiveProvinceDb($province);
            if($this->data['data'] == 200)
            {
                die('<meta charset="utf-8"><script>alert("Lưu thành công");window.location.href="'.$this->data['baseurl'].'manage/static/incentive-province";</script>');
            }
        }
        $this->data['action'] = 'incentiveprovince';
        $this->load->view('template/layout', $this->data);
    }
    
    public function addselectp()
    {
        $this->data['listProvince'] = $this->Mstaticinfo->listProvince();
        $this->data['action'] = 'ajaxaddselectp';
        $this->load->view('template/staticinfo/ajaxaddselectp', $this->data);
    }
}